package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.dto.*;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.VedioService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author Feng Chen
 */
@Controller
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private VedioService vedioService;

    @ApiOperation(value = "添加视频")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData<AddVideoVo> add(@RequestBody AddVideoDto dto) {
        return vedioService.addVedio(UserContext.get().getUserId(), dto.getTitle(), dto.getHref(), dto.getThumb(), dto.getVodId(), dto.getDraft(), dto.getLat(), dto.getLng());
    }

    @ApiOperation(value = "查询自己作品列表")
    @RequestMapping(value = "/slist", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<VideoVo> slist(int pageNumber, int pageSize) {
        return vedioService.listVedio(UserContext.get().getUserId(), null, pageNumber, pageSize);
    }

    @ApiOperation(value = "查询他人作品列表")
    @RequestMapping(value = "/olist", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "作者编号", paramType = "query", dataType = "long", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<VideoVo> olist(long userId, int pageNumber, int pageSize) {
        return vedioService.listVedio(userId, "2", pageNumber, pageSize);
    }

    @ApiOperation(value = "查询自己喜欢的列表")
    @RequestMapping(value = "/slistLike", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<LikeVideoVo> slistLike(int pageNumber, int pageSize) {
        return vedioService.listVideoLike(UserContext.get().getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "查询他人喜欢的")
    @RequestMapping(value = "/olistLike", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "作者编号", paramType = "query", dataType = "long", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<LikeVideoVo> olistLike(Long userId, int pageNumber, int pageSize) {
        return vedioService.listVideoLike(userId, pageNumber, pageSize);
    }

    @ApiOperation(value = "查询关注视频信息")
    @RequestMapping(value = "/listFocus", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<FocusVideoVo> listFocus(int pageNumber, int pageSize) {
        return vedioService.listFocus(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "查询同城视频信息")
    @RequestMapping(value = "/listScity", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lat", value = "维度", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "lng", value = "经度", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<ScityVideoVo> listScity(String lat, String lng, int pageNumber, int pageSize) {
        return vedioService.listScity(UserContext.getUserId(), lat, lng, pageNumber, pageSize);
    }

    @ApiOperation(value = "查询发现视频信息")
    @RequestMapping(value = "/listFound", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @ResponseBody
    public AjaxPage<FoundVideoVo> listFound(int pageNumber, int pageSize) {
        return vedioService.listFound(UserContext.getUserId(), pageNumber, pageSize);
    }

    @ApiOperation(value = "查询发现视频php信息")
    @RequestMapping(value = "/listFoundByPhp", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<FoundVideoByPhpVo> listFoundByPhp(int pageNumber, int pageSize) {
        return vedioService.listFoundByPhp(pageNumber, pageSize);
    }

    @ApiOperation(value = "查询关注视频信息")
    @RequestMapping(value = "/listFocusByPhp", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<FocusVideoByPhpVo> listFocusByPhp(Long userId, int pageNumber, int pageSize) {
        return vedioService.listFocusByPhp(userId, pageNumber, pageSize);
    }

    @ApiOperation(value = "查询同城视频信息")
    @RequestMapping(value = "/listScityByPhp", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "同城", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "lat", value = "维度", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "lng", value = "经度", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<ScityVideoByPhpVo> listScityByPhp(String city, String lat, String lng, int pageNumber, int pageSize) {
        return vedioService.listScityByPhp(city, lat, lng, pageNumber, pageSize);
    }

    @ApiOperation(value = "php操作动作")
    @RequestMapping(value = "/actionByPhp", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频标识", paramType = "query", dataType = "long", required = true),
            @ApiImplicitParam(name = "action", value = "动作(1-点赞 2-取消点赞 3-评论 4-分享 5-查看)", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "uid", value = "用户标识", paramType = "query", dataType = "long", required = false),
            @ApiImplicitParam(name = "touid", value = "视频用户标识", paramType = "query", dataType = "long", required = false)
            })
    @ResponseBody
    public AjaxData actionByPhp(Long videoId, String action, String uid, String touid) {
        return vedioService.actionByPhp(videoId, action, 1, touid);
    }

    @ApiOperation(value = "查询热门视频信息")
    @RequestMapping(value = "/listHot", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "int", required = false),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<HotVideoVo> listHot(Long userId, int pageNumber, int pageSize) {
        return vedioService.listHot(userId, pageNumber, pageSize);
    }


    @ApiOperation(value = "查询视频统计信息")
    @RequestMapping(value = "/getStat", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频标识", paramType = "query", dataType = "long", required = true),
    })
    @ResponseBody
    public AjaxData<VideoStatVo> getStat(Long videoId) {
        return vedioService.getStat(videoId, UserContext.getUserId());
    }

    @ApiOperation(value = "点赞视频")
    @RequestMapping(value = "/like", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData like(@RequestBody LikeVideoDto dto) {
        return vedioService.like(UserContext.getUserId(), dto.getVideoId());
    }

    @ApiOperation(value = "取消点赞视频")
    @RequestMapping(value = "/cancelLike", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData cancelLike(@RequestBody LikeVideoDto dto) {
        return vedioService.cancelLike(UserContext.getUserId(), dto.getVideoId());
    }

    @ApiOperation(value = "下载视频（记录日志）")
    @RequestMapping(value = "/download", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData download(@RequestBody DownloadVideoDto dto) {
        return vedioService.download(UserContext.getUserId(), dto.getVideoId());
    }

    @ApiOperation(value = "举报视频（记录日志）")
    @RequestMapping(value = "/report", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData report(@RequestBody ReportVideoDto dto) {
        return vedioService.report(UserContext.getUserId(), dto.getVideoId());
    }


    @ApiOperation(value = "记录查看视频时长")
    @RequestMapping(value = "/viewTime", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData viewTime(@RequestBody ViewVideoTimeDto dto) {
        return vedioService.viewTime(UserContext.getUserId(), dto.getVideoId(), dto.getTimeLong());
    }

    @ApiOperation(value = "查询热门定价列表")
    @RequestMapping(value = "/listVideoHotDef", method = RequestMethod.GET)
    @ResponseBody
    public AjaxPage<VideoHotDefVo> listVideoHotDef() {
        return vedioService.listVideoHotDef();
    }

    @ApiOperation(value = "推广视频上热门")
    @RequestMapping(value = "/buyVideoHot", method = RequestMethod.POST)
    @ApiImplicitParam(name = "dto", value = "推广视频上热门参数", dataType = "BuyVideoHotDto")
    @ResponseBody
    public AjaxData buyVideoHot(@RequestBody BuyVideoHotDto dto) {
        return vedioService.buyVideoHot(UserContext.get().getUserId(), dto.getHotId(), dto.getVideoId(),dto.getPwd());
    }

    @ApiOperation(value = "查询视频评论列表")
    @RequestMapping(value = "/listComment", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频编码", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<VideoCommentVo> listComment(Long videoId, int pageNumber, int pageSize) {
        return vedioService.listComment(videoId, pageNumber, pageSize);
    }

    @ApiOperation(value = "查询评论回复列表")
    @RequestMapping(value = "/listCommentReply", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentId", value = "评论回复", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @ResponseBody
    public AjaxPage<VideoCommentVo> listCommentReply(Long commentId, int pageNumber, int pageSize) {
        return vedioService.listCommentReply(commentId, pageNumber, pageSize);
    }

    @ApiOperation(value = "添加视频评论")
    @RequestMapping(value = "/addComment", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData<AddCommentVo> addComment(@RequestBody AddVideoCommentDto dto) {
        return vedioService.addComment(UserContext.getUserId(), dto.getContent(), dto.getReplyCommentId(), dto.getVideoId());
    }

    @ApiOperation(value = "点赞视频评论")
    @RequestMapping(value = "/likeComment", method = RequestMethod.POST)
    @ResponseBody
    public AjaxData likeComment(@RequestBody LikeVideoCommentDto dto) {
        return vedioService.likeComment(UserContext.getUserId(), dto.getCommentId());
    }


    @ApiOperation("搜索短视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "关键字", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @GetMapping("/searchVideo")
    @ResponseBody
    public AjaxPage<SearchVideoVo> searchVideo(String key, Integer pageNumber, Integer pageSize) {
        return vedioService.searchVideo(UserContext.getUserId(), key, pageNumber, pageSize);
    }

    @ApiOperation(value = "删除视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "视频标识", paramType = "query", dataType = "long", required = true),
    })
    @GetMapping("/deleteByEs")
    @ResponseBody
    public AjaxData deleteByEs(Long id) {
        return vedioService.deleteByEs(id);
    }

    @ApiOperation("添加视频")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "视频标识", paramType = "query", dataType = "long", required = true),
    })
    @GetMapping("addVideoEs")
    @ResponseBody
    public AjaxData addVideoEs(Long id) {
        return vedioService.getAddVideoEs(id);
    }

    @ApiOperation("查询视频统计数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId", value = "视频标识", paramType = "query", dataType = "long", required = true),
    })
    @GetMapping("getVideoStatNum")
    @ResponseBody
    public AjaxData<VideoStatNumVo> getVideoStatNum(Long videoId) {
        return vedioService.getVideoStatNum(videoId);
    }
}
